//  路由白名单
let writelist: string[] = ["index", "download", "activity", "business", "404"];
export default defineNuxtRouteMiddleware(async (to, from) => {
  // if (to.path != "/") {
  //   return abortNavigation();
  // }
  if (process.client) {
    const store = useStore();
    let istoken = computed(() => store.token);
    if (store.userinfo.gameID != "") {
      GetUserInfo(store.userinfo).then(({ data }: { data: any }) => {
        store.$patch({ coininfo: data.value.data.accounts });
      });
    }

    if (!writelist.includes(to.name)) {
      //校验是否有token
      if (
        istoken.value == "" ||
        istoken.value == null ||
        istoken.value == undefined
      ) {
        store.$patch({ loginopen: true });
        return abortNavigation("No permission temporarily");
      }
    }
  } else {
    // const store = useStore();
    // let istoken = computed(() => store.token);
    // // console.log(istoken.value, !writelist.includes(to.name), "istoken");
    // if (!writelist.includes(to.name)) {
    //   //校验是否有token
    //   if (
    //     istoken.value == "" ||
    //     istoken.value == null ||
    //     istoken.value == undefined
    //   ) {
    //     // store.$patch({ loginopen: true });
    //     return  navigateTo("/404");
    //   }
    // }
  }
});
